<?php

namespace addons\lysms;

use app\common\library\Menu;
use think\Addons;

/**
 * 插件
 */
class Lysms extends Addons
{

    /**
     * 插件安装方法
     * @return bool
     */
    public function install()
    {

        return true;
    }

    /**
     * 插件卸载方法
     * @return bool
     */
    public function uninstall()
    {

        return true;
    }

    /**
     * 插件启用方法
     * @return bool
     */
    public function enable()
    {

        return true;
    }

    /**
     * 插件禁用方法
     * @return bool
     */
    public function disable()
    {

        return true;
    }

    /**
     * 实现钩子方法
     * @return mixed
     */
    public function smsSend(&$param)
    {
        $config = get_addon_config('lysms');
        $post_data = [];
        $post_data['userid'] = $config['userid'];
        $post_data['account'] = $config['username'];
        $post_data['password'] = $config['password'];
        $post_data['content'] = $param->code . '【商情瞭望】';
        $post_data['mobile'] = $param->mobile;
        $post_data['sendtime'] = '';
        $url='http://sms.linyu106.com/sms.aspx?action=send';
        $o='';
        foreach ($post_data as $k=>$v)
        {
           $o.="$k=".urlencode($v).'&';
        }
        $post_data=substr($o,0,-1);
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_HEADER, 0);
        curl_setopt($ch, CURLOPT_URL,$url);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); //如果需要将结果直接返回到变量里，那加上这句。
        $result = curl_exec($ch);
        $result = xml_to_array($result);
        return $result;
    }

    /**
     * 检测验证是否正确
     * @param   Sms     $params
     * @return  boolean
     */
    public function smsCheck(&$params)
    {
        return TRUE;
    }

}
